package com.tao.design.tactics

/**
 *
 * @ProjectName:    lab
 * @Package:        com.tao.design.tactics
 * @ClassName:      Body
 * @Description:     java类作用描述
 * @Author:         wangxf
 * @CreateDate:     2022/4/24 11:26
 * @UpdateUser:     更新者
 * @UpdateDate:     2022/4/24 11:26
 * @UpdateRemark:   更新说明
 * @Version:        1.0
 */


/**
 * 行为接口
 *
 *
 *
 */
interface Behavior {
    fun fly();
}

/**
 * 抽象类
 */
abstract class Character {
    var behavior: Behavior? = null;

    fun setFlyBehavior(behavior: Behavior) {
        this.behavior = behavior;
    }

    fun performFly() {
        behavior?.fly()
    }
}

class FlyBehavior : Behavior {
    override fun fly() {
        System.out.println("i can fly")
    }
}

class FlyBody : Character() {

}

fun main() {
    val flyBody = FlyBody();
    //实现 behavior（算法/策略）的动态切换
    flyBody.setFlyBehavior(FlyBehavior())
    flyBody.performFly()
}
